package com.wp.www.controller;

import com.wp.www.entity.CommonResult;
import com.wp.www.service.StorageService;
import io.seata.core.context.RootContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
public class StorageController {

    @Resource
    private StorageService storageService;

    @GetMapping("/storage/{commodityCode}/{count}")
    public CommonResult reduceStorage(@PathVariable("commodityCode") String commodityCode, @PathVariable("count") Integer count){
        log.info("*****全局事务xid:{}", RootContext.getXID());
        Integer resultRow = storageService.reduceStorage(commodityCode, count);
        return new CommonResult(200,"库存扣减成功");
    }
}
